﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Castle.ActiveRecord;
using NHibernate.Criterion;
namespace ServiceGerenciador.Model
{
    [Serializable]
    [ActiveRecord("Agendamentos")]
    public class Agendamento : ActiveRecordBase<Agendamento>
    {
        public Agendamento()
        {

        }

        [PrimaryKey("IdAgendamento")]
        public int Id { get; set; }

        [BelongsTo("IdFuncionario")]
        public Funcionario Funcionario { get; set; }

        [BelongsTo("IdServico")]
        public Service Servico { get; set; }

        [Property("DataAgendamento")]
        public DateTime Date { get; set; }

        [Property("IniDateTime")]
        public string InitialDateTime { get; set; }

        [Property("FinalDateTime")]
        public string FinalDateTime { get; set; }

        [Property("Descricao")]
        public string Description { get; set; }

        [Property("Obs")]
        public string Obs { get; set; }

        [Property("Concluido")]
        public bool Concluido { get; set; }

        public static Agendamento GetAppointmentDatetime(TimeSpan initialDateTime, TimeSpan finalDateTime, DateTime date)
        {
            ICriterion[] query = 
            {
                Expression.Eq("IniDateTime", initialDateTime),
                Expression.Eq("FinalDateTime", finalDateTime),
            };

            return FindAll(query).FirstOrDefault();
        }
    }
}